pub mod config;

use std::path::{Path, PathBuf};

/// 获取rust-cmaker文件夹目录
pub fn get_home_path() -> PathBuf {
    let path = std::env::current_exe().unwrap();
    let path = path.parent().unwrap().to_path_buf();
    path.parent().unwrap().to_path_buf()
}

/// 复制文件夹到指定路径
pub fn copy_dir(src: &Path, dst: &Path) -> std::io::Result<()> {
    if src.is_file() {
        return Err(std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            "源路径必须是一个文件夹",
        ));
    }

    if !dst.exists() {
        std::fs::create_dir_all(dst)?;
    }

    for entry in std::fs::read_dir(src)? {
        let entry = entry?;
        let path = entry.path();
        let dst_path = dst.join(path.file_name().unwrap());

        if entry.file_type()?.is_dir() {
            copy_dir(&path, &dst_path)?;
        } else {
            std::fs::copy(&path, &&dst_path)?;
        }
    }

    Ok(())
}
